/*
** 作者：TheBadZhang
** 创建时间：200509
** 最后修改时间：看文件
** 文件名：music.hpp
** 用途：音乐播放
*/
#ifndef isMusicIsDefine
#define isMusicIsDefine
// 真的是成吨成吨的工作要做，我对音乐一窍不通，简单先弄两下吧
#include "xege.h"
// https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html
class MUSIC {
private:
	Mix_Chunk* chunk;
	int volume;
	Mix_Music* music;


	void loadFromBuffer (Uint8* buffer) {
		chunk = Mix_QuickLoad_WAV (buffer);
		if (chunk == nullptr) {
			SDL_Log ("Mix_QuickLoad_WAV error: %s", Mix_GetError ());
		}
	}
public:
	MUSIC () {

	}
	~MUSIC () {
		Mix_FreeChunk (chunk);
		chunk = nullptr;
	}
	void load (std::string filepath) {
		// This can load WAVE, AIFF, RIFF, OGG, and VOC files.
		chunk = Mix_LoadWAV (filepath.c_str ());
		if (chunk == nullptr) {
			SDL_Log ("Mix_LoadWAV error: %s", Mix_GetError ());
			SDL_Quit ();
		}
	}
	void setVolume (int x) {
		volume = x;
		Mix_VolumeChunk (chunk, x);
	}
	void pause (void) {
		// Mix_Pause ()
	}
	void setPosition (void) {
		
	}
	void play (void) {

	}
	void restart () {

	}
	void close () {
		// or name toend ?
	}

};

#endif